package com.cs.cssupplier.controller;

import com.cs.cssupplier.domain.CsAccessories;
import com.cs.cssupplier.domain.CsAchievement;
import com.cs.cssupplier.mapper.CsWinningResultsMapper;
import com.cs.cssupplier.service.CsAchievementService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：lyj
 * @Package：com.cs.cssupplier.controller
 * @Project：RuoYi-Cloud-master
 * @name：CsAchievementController
 * @Date：2024/11/14 15:16
 * @Filename：CsAchievementController
 */
@RestController
@RequestMapping("/achievement")
public class CsAchievementController extends BaseController{
    @Resource
    private CsAchievementService csAchievementService;
    @Autowired
    private CsWinningResultsMapper mapper;
    /**
     * 根据id查询业绩信息
     * @param yj_id
     * @return
     */
    @GetMapping(value = "cd/{yj_id}")
    public AjaxResult achievementId(@PathVariable("yj_id")Long yj_id){
        System.out.println(AjaxResult.success(csAchievementService.selectAchievementyjId(yj_id)));
        return AjaxResult.success(csAchievementService.selectAchievementyjId(yj_id));
    }

    /**
     * 查询所有业绩信息
     * @param csAchievement
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(CsAchievement csAchievement){
        startPage();
        List<CsAchievement> list=csAchievementService.selectAchievementList(csAchievement);
        return getDataTable(list);
    }

    /**
     * 添加业绩信息
     * @param csAchievement
     * @return
     */
    @PostMapping
    public AjaxResult insertAchievement(@RequestBody CsAchievement csAchievement){
        return toAjax(csAchievementService.addAchievement(csAchievement));
    }

    /**
     * 修改业绩信息
     * @param csAchievement
     * @return
     */
    @PutMapping
    public AjaxResult updateAchievement(@RequestBody CsAchievement csAchievement){
        Long userid = SecurityUtils.getLoginUser().getUserid();
        Long sipplierByUserId = mapper.getSipplierByUserId(userid);//这才是供应商id
        csAchievement.setHid(sipplierByUserId);
        System.out.println(csAchievementService.updateAchievement(csAchievement));
        return toAjax(csAchievementService.updateAchievement(csAchievement));
    }

    /**
     * 批量修改业绩信息
     * @param yj_id
     * @return
     */
    @DeleteMapping("/{yj_id}")
    public AjaxResult deleteAchievement(@PathVariable Long [] yj_id){
        return toAjax(csAchievementService.deleteListAchievement(yj_id));
    }
}
